import axios from 'axios'
import {getToken} from "@/utils/auth";
// 设置请求主体主要是json
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
const request = axios.create({
    // axios中请求配置有baseURL选项，表示请求URL公共部分
    baseURL: "http://localhost:9000",
    // 超时
    timeout: 15000,
    withCredentials:false
})
request.interceptors.request.use(config => {
    if (getToken()) {
        config.headers['token'] = getToken() // 让每个请求携带自定义token
    }
    return config
}, error => {
    Promise.reject(error).then(r => {})
})
export default request
